<template>

    <div class="contain">
        <div class="header">
            <el-button class="link" type="primary" >
                 <router-link  to="/informEdit" style="color: #fff;">新增公告</router-link>
            </el-button>
        </div>
        <div class="input_modal">
            <div class="input-item">
                <el-input v-model="searchWord" placeholder="请输入公告ID或标题" class="proName"  @keyup.enter.native="search"></el-input>
                <el-button type="primary" @click="getInformList">公告查询</el-button>
            </div>
        </div>
        
        <div class="table_con">
            <el-table :data="tableData" stripe style="width: 100%">
                <el-table-column prop="newsId" label="公告ID">
                </el-table-column>
                <el-table-column prop="newsTitle" label="公告标题">
                </el-table-column>
                <el-table-column prop="publishTime" label="发布日期">
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                    <el-button type="primary" plain size="mini" @click="linkToEdit(tableData[scope.$index].newsId)">修改</el-button>
                    <el-button type="danger" plain size="mini" @click="deleteItem(tableData[scope.$index].newsId)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        
        <div class="pagination">
             <el-pagination   @size-change="handleSizeChange"  @current-change="handleCurrentChange"       
                :current-page.sync="pageIndex"              
                :page-size="pageSize"   
                :page-sizes='[10,20,30,40]'    
                layout="sizes, prev, pager, next"       
                :total="pageCount">     
            </el-pagination>
        </div>
    </div>
</template>

<script>
let CONSTANT = require('../../constant/constant.js');
let common = require("../../common.js");
export default {
    data() {
        
        return {
            searchWord:'',
            newsId:'',
            newsTitle:'',
            newsContent:'',
            publishTime:'',
            tableData:[],
            pageCount:null,
            pageIndex:1,
            pageSize:10,
            loading:true,
            dialogVisible:false,
            dialogTitle:'操作提示',
            dialogType:'camp',
            rules: {
                
            },
        }
    },
    mounted() {
        this.getInformList()
    },
    methods: {
        getInformList:function(){  // FINDAPPUSERBYPAGE
            console.log('点击查询');
            console.log(this.searchWord);
            let url = CONSTANT.URL.INFORM.FINDVOTENEWSBYPAGE;
            let dataForm = {
                pageIndex:this.pageIndex,
                pageSize:this.pageSize,
            }
            let data = {
                searchWord:this.searchWord,               
                
            } ;
            if(this.searchWord != ''){
                    data.searchWord = this.searchWord;
            }
            let param = JSON.stringify(data);
            this.loading = true;
                common.requestAjax(url,param,dataForm,(res)=>{
                    this.loading = false;
                    let data = res.data;
                    this.tableData = data.bussData;
                    this.pageCount = data.pageCount*this.pageSize;
                    // console.log('data',data);
                }) 
        },
        search:function(e){
            if(e.keyCode == 13){
                this.pageIndex = 1;                 
                this.getInformList();
            }
        },
        handleSizeChange(val) {
            this.pageSize= val;
            this.getInformList(this.pageIndex);
        },
        handleCurrentChange(val) {
            this.getInformList(val);
            this.pageIndex = val;
        },
        linkToEdit(id){
            console.log(id);
            this.$router.push({path:'/informEdit',query:{'id':id}}); 
        },
        deleteItem:function(id){
            console.log('delete-----id', id);
            this.$confirm('确定删除?', '提示', {           
                confirmButtonText: '确定',           
                cancelButtonText: '取消',           
                type: 'warning'         
            }).then(() => {           
                let  url = CONSTANT.URL.INFORM.DELVOTENEWS
                let param = {newsId:id};
                common.requestAjax(url,param,null,(res)=>{
                    if(res.status == 200){
                        this.$message({
                            type:'success',
                            message:'删除成功!'
                        });
                        this.getInformList();
                    }
                    else{
                        this.$message({
                            type:'warning',
                            message:res.msg
                        })
                    }
                })      
            }).catch(() => {           
                this.$message({             
                    type: 'danger',             
                    message: '已取消删除'           
                });                   
            });    
        },
        handleClose(){
            this.dialogVisible = false;
        },

    },
}
</script>

<style lang="scss" scoped>
    .contain {
         .header{
            margin: 20px 0;
            padding-bottom: 10px;
            border-bottom:1px solid #dedede; 
        }
        .input_modal {
            margin-top: 20px;
            .input-item{ 
                display: inline-block;
                margin-right: 20px;
                clear: both;
                height: 40px;
                line-height: 40px;
                .el-input,.el-button, .el-select,span{ float: left;margin-right: 10px;}
                .proName{width:200px;}
            }
        }
        .el-dialog__body{
            // padding:  10px 20px;
            .dialog-con{
                padding:0px 20px 0px 0px;
                p{  text-align: center;margin:5px 0px 20px 0px;font-size: 14px;color: #666;
                    span{
                        color: #111;font-size: 14px;
                    }
                }
            }
        }
        .table_con{
            // .el-button{
            //     display: inline-block;
            //     width: 104px;
            //     height: 30px;
            //     margin-left: 0;
            //     margin-top: 5px;
            // }
            // .el-button:nth-child(3){
            //      margin-top: 5px;
            // }
            text-align: center;
        }
        .pagination {
            text-align: right;
            width: 100%;
            margin-top: 60px;
        }
    }
</style>
